using System;
using ICSharpCode.NRefactory.CSharp;
using Xunit;

namespace Framework.Tests.Refactoring
{
    public static class ModifiersExtension
    {
        public static bool IsLessAccessible(this Modifiers modifiers, Modifiers target)
        {
            if (!IsVisibilityModifiers(modifiers))
            {
                throw new ArgumentException("modifiers must be a visility modifiers");
            }

            if (!IsVisibilityModifiers(target))
            {
                throw new ArgumentException("modifiers must be a visility modifiers");
            }

            return modifiers > target;
        }

        private static bool IsVisibilityModifiers(Modifiers modifiers)
        {
            return (modifiers & Modifiers.VisibilityMask) != Modifiers.None;
        }
    }

    // ReSharper disable UnusedMember.Global
    public class ModifiersExtensionTest
    // ReSharper restore UnusedMember.Global
    {
        [Fact]
        // ReSharper disable InconsistentNaming
        // ReSharper disable UnusedMember.Global
        public void Should_throw_argument_exception_when_modifiers_is_not_visibility_modifiers()
        // ReSharper restore UnusedMember.Global
        // ReSharper restore InconsistentNaming
        {
            Assert.Throws<ArgumentException>(() => Modifiers.Virtual.IsLessAccessible(Modifiers.Public));
            Assert.Throws<ArgumentException>(() => Modifiers.Public.IsLessAccessible(Modifiers.Virtual));
        }

        [Fact]
        // ReSharper disable InconsistentNaming
        // ReSharper disable UnusedMember.Global
        public void Should_return_true_when_modifiers_is_not_less_accessible_than_target()
        // ReSharper restore UnusedMember.Global
        // ReSharper restore InconsistentNaming
        {
            Assert.True(Modifiers.Public.IsLessAccessible(Modifiers.Internal));
        }

        [Fact]
        // ReSharper disable InconsistentNaming
        // ReSharper disable UnusedMember.Global
        public void Should_return_false_when_modifiers_is_less_accessible_than_target()
        // ReSharper restore UnusedMember.Global
        // ReSharper restore InconsistentNaming
        {
            Assert.False(Modifiers.Internal.IsLessAccessible(Modifiers.Public));
        }
    }
}